{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "QUANTAXIS>> start QUANTAXIS\n",
      "QUANTAXIS>> Welcome to QUANTAXIS, the Version is 1.1.0\n",
      "QUANTAXIS>>  \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``########`````##````````##``````````##`````````####````````##```##########````````#``````##``````###```##`````######`` \n",
      "  `##``````## ```##````````##`````````####````````##`##```````##```````##```````````###``````##````##`````##```##`````##` \n",
      "  ##````````##```##````````##````````##`##````````##``##``````##```````##``````````####```````#```##``````##```##``````## \n",
      "  ##````````##```##````````##```````##```##```````##```##`````##```````##`````````##`##```````##`##```````##````##``````` \n",
      "  ##````````##```##````````##``````##`````##``````##````##````##```````##````````##``###```````###````````##`````##`````` \n",
      "  ##````````##```##````````##``````##``````##`````##`````##```##```````##```````##````##```````###````````##``````###```` \n",
      "  ##````````##```##````````##`````##````````##````##``````##``##```````##``````##``````##`````##`##```````##````````##``` \n",
      "  ##````````##```##````````##````#############````##```````##`##```````##`````###########`````##``##``````##`````````##`` \n",
      "  ###```````##```##````````##```##```````````##```##```````##`##```````##````##`````````##```##```##``````##```##`````##` \n",
      "  `##``````###````##``````###``##`````````````##``##````````####```````##```##``````````##``###````##`````##````##`````## \n",
      "  ``#########``````########```##``````````````###`##``````````##```````##``##````````````##`##``````##````##`````###``### \n",
      "  ````````#####`````````````````````````````````````````````````````````````````````````````````````````````````````##``  \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      "  ``````````````````````````Copyright``yutiansut``2018``````QUANTITATIVE FINANCIAL FRAMEWORK````````````````````````````` \n",
      "  ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` \n",
      " \n"
     ]
    }
   ],
   "source": [
    "import QUANTAXIS as QA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "account=QA.QA_Account(account_cookie='future_1',allow_t0=True,allow_sellopen=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'source': 'account',\n",
       " 'account_cookie': 'future_1',\n",
       " 'portfolio_cookie': None,\n",
       " 'user_cookie': None,\n",
       " 'broker': 'backtest',\n",
       " 'market_type': 'stock_cn',\n",
       " 'strategy_name': None,\n",
       " 'current_time': 'None',\n",
       " 'allow_sellopen': True,\n",
       " 'allow_t0': True,\n",
       " 'margin_level': False,\n",
       " 'init_assets': {'cash': 1000000, 'hold': {}},\n",
       " 'commission_coeff': 0.00025,\n",
       " 'tax_coeff': 0.0015,\n",
       " 'cash': [1000000],\n",
       " 'history': [],\n",
       " 'trade_index': [],\n",
       " 'running_time': '2018-08-23 09:54:14.005020',\n",
       " 'quantaxis_version': '1.1.0',\n",
       " 'running_environment': 'backtest'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "account.message"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "< QA_Order realorder_id Order_pgXJEKQY datetime:2018-08-23 09:31:00 code:RB1810 amount:1000 price:800 towards:-1 btype:stock_cn order_id:Order_pgXJEKQY account:future_1 status:queued >"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "account.send_order('RB1810',amount=1000,time='2018-08-23 9:50:00',towards=QA.ORDER_DIRECTION.SELL_OPEN,price=800,order_model=QA.ORDER_MODEL.LIMIT,amount_model=QA.AMOUNT_MODEL.BY_AMOUNT)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>active1</th>\n",
       "      <th>active2</th>\n",
       "      <th>last_close</th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>price</th>\n",
       "      <th>cur_vol</th>\n",
       "      <th>...</th>\n",
       "      <th>bid3</th>\n",
       "      <th>bid_vol3</th>\n",
       "      <th>ask4</th>\n",
       "      <th>ask_vol4</th>\n",
       "      <th>bid4</th>\n",
       "      <th>bid_vol4</th>\n",
       "      <th>ask5</th>\n",
       "      <th>ask_vol5</th>\n",
       "      <th>bid5</th>\n",
       "      <th>bid_vol5</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>000001</th>\n",
       "      <td>2018-08-23 10:09:40.716973</td>\n",
       "      <td>770</td>\n",
       "      <td>770</td>\n",
       "      <td>9.29</td>\n",
       "      <td>000001</td>\n",
       "      <td>9.3</td>\n",
       "      <td>9.42</td>\n",
       "      <td>9.3</td>\n",
       "      <td>9.34</td>\n",
       "      <td>70</td>\n",
       "      <td>...</td>\n",
       "      <td>9.31</td>\n",
       "      <td>1865</td>\n",
       "      <td>9.37</td>\n",
       "      <td>1967</td>\n",
       "      <td>9.3</td>\n",
       "      <td>2282</td>\n",
       "      <td>9.38</td>\n",
       "      <td>2740</td>\n",
       "      <td>9.29</td>\n",
       "      <td>3788</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 33 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                         datetime  active1  active2  last_close    code  open  \\\n",
       "code                                                                            \n",
       "000001 2018-08-23 10:09:40.716973      770      770        9.29  000001   9.3   \n",
       "\n",
       "        high  low  price  cur_vol    ...     bid3  bid_vol3  ask4  ask_vol4  \\\n",
       "code                                 ...                                      \n",
       "000001  9.42  9.3   9.34       70    ...     9.31      1865  9.37      1967   \n",
       "\n",
       "        bid4  bid_vol4  ask5  ask_vol5  bid5  bid_vol5  \n",
       "code                                                    \n",
       "000001   9.3      2282  9.38      2740  9.29      3788  \n",
       "\n",
       "[1 rows x 33 columns]"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "QA.QA_fetch_get_stock_realtime('tdx','000001')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
